package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.DeviceBean;
import com.koron.css2.baseConfig.mapper.DeviceMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class DeviceSelect implements ServerInterface {

    private static final Logger logger = LoggerFactory.getLogger(DeviceSelect.class);

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);

        List<DeviceBean> deviceBeans = null;
        try {
            DeviceMapper deviceMapper = factory.getMapper(DeviceMapper.class);
            deviceBeans = deviceMapper.selectDeviceInfo();
        } catch (Exception e) {
            info.setCode(Constant.MESSAGE_INT_FAIL);
            info.setDescription(e.getMessage());
            logger.error(e.getMessage(), e);
        }

        info.setData(deviceBeans);
        return info;
    }
}
